﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Common.XmlConfig;

namespace ZWZ.Web.WebAdmin
{
    public partial class cfg : System.Web.UI.Page
    {
        private string CONFIGKEY
        {
            get
            {
                if (string.IsNullOrEmpty(Request["key"]))
                {
                    return "SiteSettingMgr";
                }
                else
                {
                    return Request["key"];
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {

        }
        protected void BindData()
        {
            var groups = Config.ConfigAdapter.GetManager(CONFIGKEY).Groups;
            Rpt_Tabs.DataSource = groups;
            Rpt_Tabs.DataBind();
            Rpt_Ctns.DataSource = groups;
            Rpt_Ctns.DataBind();
        }
        protected void Rpt_Ctns_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var group = e.Item.DataItem as Common.XmlConfig.ConfigGroup;
            Repeater Rpt_Setting = e.Item.FindControl("Rpt_Setting") as Repeater;
            Rpt_Setting.DataSource = group.Settings;
            Rpt_Setting.DataBind();
        }
        protected void Rpt_Setting_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label Label1 = e.Item.FindControl("Label1") as Label;
            Label Label2 = e.Item.FindControl("Label2") as Label;
            Literal Literal1 = e.Item.FindControl("Literal1") as Literal;
            ConfigSetting setting = e.Item.DataItem as ConfigSetting;
            Label1.Text = setting.Text;
            Literal1.Text = Config.ConfigAdapter.GetHtml(setting);
            Label2.Text = string.IsNullOrEmpty(setting.Tip) ? Label2.Text = "设置" + setting.Text : setting.Tip;
        }
    }
}